package com.sumainfor.pc.gmio.service.impl;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.gmio.dao.WatGasEleExsMapper;
import com.sumainfor.pc.gmio.feign.Zfeign.ZpcMktFeign;
import com.sumainfor.pc.gmio.feign.Zfeign.ZwxTenantFeign;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.print.DocFlavor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Meng
 * @ClassName WatGasEleExsServiceImpl
 * @date 2020/2/19 9:57
 * @description: TODO
 */
@Service
public class WatGasEleExsServiceImpl {

    @Autowired
    WatGasEleExsMapper watGasEleExsMapper;

    @Autowired
    ZpcMktFeign zpcMktFeign;
    @Autowired
    ZwxTenantFeign zwxTenantFeign;


    public Map<String,Object> getGEW(Map<String,Object> params){
        return watGasEleExsMapper.getGEW(params);
    }


    public Map<String,Object> getGEWOut(Map<String,Object> params){
        return watGasEleExsMapper.getGEWOut(params);
    }

    public List<Map<String,Object>> getGEWTuiZu(Map<String,Object> params){
        return  watGasEleExsMapper.getGEWTuiZu(params);
    }

    public List<Map<String,Object>> getGEWTuiZuOut(Map<String,Object> params){
        return watGasEleExsMapper.getGEWTuiZuOut(params);
    }

    public List<Map<String,Object>> getRoomMoney(Map<String,Object> params){
        return watGasEleExsMapper.getRoomMoney(params);
    }

    /**
     * 退房款项支出表
     * @param params
     * @param pager
     * @return
     */
    public JsonResult HousKeepRoomList(Map<String,Object> params,Pager pager){

        JsonResult result = new JsonResult();

        pager.setPageno((Integer) params.get("pageno"));
        pager.setPagesize((Integer) params.get("pagesize"));
        pager.setPagerNecessary(params,pager);
        PageUtils pageUtils = new PageUtils();
        List<String> HouList = new ArrayList<>();
        List<Map<String,Object>> getHoulist =  zpcMktFeign.getHoulist(params);
        if (getHoulist.size()>0){

            for (Map<String,Object> map1:getHoulist){
                HouList.add(MapUtils.getString(map1,"HouId"));

            }
        }

        if (HouList.size()>0){
            params.put("HouList",HouList);
        }

        Integer cout = watGasEleExsMapper.getWithdrawalOut(params);
        if(cout == 0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(),params,cout);
        }else {
            List<Map<String, Object>> getWithdrawalList = watGasEleExsMapper.getWithdrawalList(params);

            for (Map<String,Object> map2:getWithdrawalList){

                  String HouInfoId = MapUtils.getString(map2,"HouInfoId");
                  String cod = HouInfoId.substring(HouInfoId.length()-1,HouInfoId.length());
                  map2.put("cod",cod);

                List<Map<String,Object>> getHoulists = zpcMktFeign.getHoulist(map2);

                Map<String,Object> ceshiMap = getHoulists.get(0);
                map2.putAll(ceshiMap);
                //获取退租人信息
                map2.putAll(zwxTenantFeign.getTenantXinxi(map2));



            }
            return pageUtils.getJsonResult(getWithdrawalList,params,cout);
        }

    }



    public Map<String,Object> getcharge(Map<String,Object> params){
        return watGasEleExsMapper.getcharge(params);
    }


    public Map<String,Object> getWatNumber(Map<String,Object> params){
        return watGasEleExsMapper.getWatNumber(params);
    }

    public Map<String,Object> getGasNumber(Map<String,Object> params){
        return watGasEleExsMapper.getGasNumber(params);
    }

    public Map<String,Object> getEleNumber(Map<String,Object> params){
        return watGasEleExsMapper.getEleNumber(params);
    }


    public List<Map<String,Object>> getOwerdeal(Map<String,Object> params){
        return watGasEleExsMapper.getOwerdeal(params);
    }


    public Map<String,Object> getTenwithdrawal(Map<String,Object> params){
        return watGasEleExsMapper.getTenwithdrawal(params);
    }

}
